package com.bite.principle.controller;

import com.bite.principle.model.Dog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DogController {
    @Autowired
    private ApplicationContext context;

    @Autowired
    private Dog singletonDog;

    @Autowired
    private Dog prototypeDog;

    @Autowired
    private Dog requestDog;


    @Autowired
    private Dog sessionDog;

    @Autowired
    private Dog applicationDog;

    @RequestMapping("/single")
    public String single(){
        //从context获取对象
        Dog contexDog = context.getBean("singletonDog",Dog.class);
        return "contextDog:"+contexDog +",autowiredDog:"+singletonDog;
    }

    @RequestMapping("/prototype")
    public String prototype(){
        //从context获取对象
        Dog contexDog = context.getBean("prototypeDog",Dog.class);
        return "contextDog:"+contexDog +",<br/> autowiredDog:"+prototypeDog;
    }


    @RequestMapping("/request")
    public String request(){
        //从context获取对象
        Dog contexDog = context.getBean("requestDog",Dog.class);
        return "contextDog:"+contexDog +",<br/> autowiredDog:"+requestDog;
    }

    @RequestMapping("/session")
    public String session(){
        //从context获取对象
        Dog contexDog = context.getBean("sessionDog",Dog.class);
        return "contextDog:"+contexDog +",<br/> autowiredDog:"+sessionDog;
    }

    @RequestMapping("/application")
    public String application(){
        //从context获取对象
        Dog contexDog = context.getBean("applicationDog",Dog.class);
        return "contextDog:"+contexDog +",<br/> autowiredDog:"+applicationDog;
    }
}
